< previous page page_316 next page >

Page 316
warning.gif
If you plan to run your database application using any 16-bit data tool, you'll need to store the database in the Microsoft Jet 2.5 version. Only Microsoft Jet 2.5 can run on both 32- and 16-bit platforms.

Using the RegisterDatabase Method
The RegisterDatabase method enables you to register an ODBC data source for Microsoft Jet access. The Visual Basic documentation encourages programmers to rely on the Windows Control Panel ODBC Setup utility rather than using the RegisterDatabase method. If, however, you want to perform the ODBC registration process within your Visual Basic program, you can use the RegisterDatabase method to do so.
The easiest way to provide ODBC registration capabilities in your program is to supply a limited number of parameters and force Windows to present the ODBC registration dialog for youa fairly easy task. For this example, add a new command button to the bottom of the form. Set its Name property to cmdDBRegister and its Caption property to DBRegister. Add the code in Listing 9.5.
Type.gifListing 9.5. Coding a DBRegistration routine.
Private Sub cmdDBRegister_Click()
    '
    ' invoke ODBC registration
    '
    On Error Resume Next
    '
    Dim strDSN As String
    Dim strDriver As String
    Dim blnQuiet As Boolean
    Dim strAttrib As String
    Dim strDelim As String
    '
    strDelim = Chr(0)
    strDSN = "TDPSample"
    strDriver = "SQL Server"
    blnQuiet = False
    strAttrib = "SERVER=\\SQLSERVER2" & strDelim
    strAttrib = strAttrib & "DATABASE=ProductionData" & strDelim
    strAttrib = strAttrib & "DESCRIPTION=Sample ODBC Registration" & strDelim
    '
    DBEngine.RegisterDatabase strDSN, strDriver, blnQuiet, strAttrib
    '
End Sub

 
< previous page page_316 next page >

If you like this book, buy it!